<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018/8/22 0022
 * Time: 17:22
 */
namespace app\admin\model;
use think\Db;

class ClockModel
{
    /**获取clock模型
     * @return $this
     */
    static public function getClock(){
        return Db::view('punch_clock',true)
            ->view('user','user,openid,nickname,portrait,sex,phone,email,integral,fabulous','user.id=punch_clock.userid','left')
            ->view('company','company_name','punch_clock.company_id=company.id','left')
            ->view('departmen_table','departmen_name,number','departmen_table.id=punch_clock.departmen_id','left');
    }

    /**添加打卡记录表
     * @param $data
     * @return int|string
     */
    static public function addClock($data){
        return Db::name('punch_clock')->insert($data);
    }

    /**删除打卡记录
     * @param $field
     * @param null $op
     * @param null $condition
     * @return int
     */
    static public function delClock($field, $op = null, $condition = null){
        return Db::name('punch_clock')->where($field,$op,$condition)->delete();
    }

    /**更新打卡记录
     * @param $data
     * @return bool|int|string
     */
    static public function updateClock($data){
        if(isset($data['id'])){
            return Db::name('punch_clock')->where('id',$data['id'])->update($data);
        }else{
            return false;
        }
    }
}